package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class BibliotecaApp {

    private Input input;
    private Output output;
    private ArrayList<String> options;
    public boolean signedIn;
    public User user;
    private HashMap<Integer,Command> commands;

    private List<Command> commandList;
    private Library library;



    public BibliotecaApp(Input input, Output output, List<Command> commands, Library library) {
        this.options = new ArrayList<String>();
        this.options.add("See List of Books");
        this.options.add("Reserve Book");
        this.options.add("Check Membership");
        this.options.add("See List of Movies");
        this.input = input;
        this.output = output;
        this.library = library;
        this.commandList = commands;

        this.commands = new HashMap<Integer, Command>();
        for(int i=0; i< commands.size(); i++)
        {
            this.commands.put(i, commands.get(i));
        }
    }

    private boolean notValidOptionCheck(int option)
    {
        if (option < 0 || option >= options.size()) {

            output.printValidOptionPrompt();
            return true;
        }
        else {
            return false;
        }
    }


    public void processMenuOption(int option) {
        if(notValidOptionCheck(option))
            return;

        commands.get(option).execute(option, library.hasValidatedUser());
    }



    public void start() {
        output.welcome();
        this.validateUserPassword();
        output.printCommands(commandList);
        this.processMenuOption(input.getUserInput());
    }

    public void validateUserPassword() {
        output.printUsernamePrompt();
        String username = input.getUserStringInput();
        output.printPasswordPrompt();
        String password = input.getUserStringInput();
        library.validateUserPassword(username, password);

    }

}
